    /*
     *批量导入excel表格数据
     */
    public function importExcel() {
   
        $this->display('importExcel');

        if(!empty($_FILES['file']['name'])){
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize  = 3145728 ;// 设置附件上传大小
            $upload->allowExts  = array('xlsx', 'xls');// 设置附件上传类型
            $upload->rootPath  =     './Public/Admin/Uploads/'; // 设置附件上传根目录
            $upload->savePath  =     'Sy/'; // 设置附件上传（子）目录
            $upload->autoSub   = true;
            $upload->subName = array('date','Ymd');

            if(!$info = $upload->upload()) {
                // 上传错误提示错误信息
                echo '文件上传失败，失败原因:'.$upload->getError();
                exit;               
            }
            
            $uploaded_file_path = $upload->rootPath.$info['file']['savepath'].$info['file']['savename'];
         
            $result=import_excel($uploaded_file_path);

            $len_result = count($result)>0?count($result)-1:0;
            if ($len_result == 0) {
                echo '没有任何数据！';
                exit;
            }

            $time=time();  
            $datetime=date('Y-m-d H:i:s',$time);

            ${$tableName}Model=D('{$TableName}');


            $table = "<table border='1'><tr><th>行数</th>
                  <if condition="count($listFieldArr) AND is_array($listFieldArr)">
                    <volist name="listFieldArr" id="vvo" key="iio">
                      <volist name="tableInfoArray" id="tableInfo">
                        <if condition="($tableInfo[$columnNameKey] eq $vvo) AND ($tableInfo['column_key'] neq 'PRI') AND ($tableInfo[$columnNameKey] neq 'add_time') AND ($tableInfo[$columnNameKey] neq 'update_time') AND ($tableInfo[$columnNameKey] neq 'add_admin_id') AND ($tableInfo[$columnNameKey] neq 'add_admin_name')">
                          <if condition="count($fieldAliasArr) AND isset($fieldAliasArr[$tableInfo[$columnNameKey]]) AND ($fieldAliasArr[$tableInfo[$columnNameKey]] neq '')">
                            <th>{$fieldAliasArr[$tableInfo[$columnNameKey]]}</th>
                          <else/>
                            <if condition="$tableInfo['column_comment'] neq ''">
                              <th>{$tableInfo[column_comment]}</th>
                            <else/>
                              <th>{$tableInfo[$columnNameKey]}</th>
                            </if>
                          </if>
                        </if>
                      </volist>
                    </volist>
                  </if>              
              <th>导入是否成功</th><th>导入失败原因</th></tr>";

            $cnt = 0;  //成功导入总条数

            foreach($result as $k=>$v){
                if($k>1){
                    <if condition="count($listFieldArr) AND is_array($listFieldArr)">
                      <php>$getExcelColumn=0;</php>
                      <volist name="listFieldArr" id="vvo" key="iio">
                        <volist name="tableInfoArray" id="tableInfo">
                          <if condition="($tableInfo[$columnNameKey] eq $vvo) AND ($tableInfo['column_key'] neq 'PRI') AND ($tableInfo[$columnNameKey] neq 'add_time') AND ($tableInfo[$columnNameKey] neq 'update_time') AND ($tableInfo[$columnNameKey] neq 'add_admin_id') AND ($tableInfo[$columnNameKey] neq 'add_admin_name')">
                             <if condition="($tableInfo['data_type'] eq 'int') OR ($tableInfo['data_type'] eq 'tinyint') OR ($tableInfo['data_type'] eq 'smallint') OR ($tableInfo['data_type'] eq 'mediumint') OR ($tableInfo['data_type'] eq 'integer') OR ($tableInfo['data_type'] eq 'bigint')">    
                                    ${$vvo}=(int)trim($v[{$getExcelColumn}]);
                             <else/>
                                    ${$vvo}=trim($v[{$getExcelColumn}]);        
                             </if> 
                             <php>$getExcelColumn=$getExcelColumn+1;</php>
                          </if>
                        </volist>
                      </volist>
                    </if> 


                	if(
                    <if condition="count($listFieldArr) AND is_array($listFieldArr)">
                      <php>$getExcelColumn=0;</php>
                      <volist name="listFieldArr" id="vvo" key="iio">
                        <volist name="tableInfoArray" id="tableInfo">
                          <if condition="($tableInfo[$columnNameKey] eq $vvo) AND ($tableInfo['column_key'] neq 'PRI') AND ($tableInfo[$columnNameKey] neq 'add_time') AND ($tableInfo[$columnNameKey] neq 'update_time') AND ($tableInfo[$columnNameKey] neq 'add_admin_id') AND ($tableInfo[$columnNameKey] neq 'add_admin_name')">
                             <if condition="$getExcelColumn gt 0">&&</if>
                             <if condition="($tableInfo['data_type'] eq 'int') OR ($tableInfo['data_type'] eq 'tinyint') OR ($tableInfo['data_type'] eq 'smallint') OR ($tableInfo['data_type'] eq 'mediumint') OR ($tableInfo['data_type'] eq 'integer') OR ($tableInfo['data_type'] eq 'bigint')">    
                                    !empty(${$vvo})
                             <else/>
                                    ${$vvo}!=''       
                             </if> 
                             <php>$getExcelColumn=$getExcelColumn+1;</php>
                          </if>
                        </volist>
                      </volist>
                    </if>                     
                  ){
        	    		  ${$originalTableName}_insert_data = array();    		   

                    <if condition="count($listFieldArr) AND is_array($listFieldArr)">
                      <volist name="listFieldArr" id="vvo" key="iio">
                        <volist name="tableInfoArray" id="tableInfo">
                          <if condition="($tableInfo[$columnNameKey] eq $vvo) AND ($tableInfo['column_key'] neq 'PRI') AND ($tableInfo[$columnNameKey] neq 'add_time') AND ($tableInfo[$columnNameKey] neq 'update_time') AND ($tableInfo[$columnNameKey] neq 'add_admin_id') AND ($tableInfo[$columnNameKey] neq 'add_admin_name')">
                            ${$originalTableName}_insert_data['{$vvo}'] =${$vvo};
                            <php>echo "\r\n\t\t\t";</php>  
                          </if>
                        </volist>
                      </volist>
                    </if> 

                    <volist name="tableInfoArray" id="tableInfo">
                      <if condition="($tableInfo[$columnNameKey] eq 'add_time')">
                        <if condition="($tableInfo['data_type'] eq 'int')">
                            ${$originalTableName}_insert_data['add_time'] =$time;
                        <else/>
                            ${$originalTableName}_insert_data['add_time'] =$datetime;
                        </if>
                      </if>

                      <if condition="($tableInfo[$columnNameKey] eq 'update_time')">
                        <if condition="($tableInfo['data_type'] eq 'int')">
                            ${$originalTableName}_insert_data['update_time'] =$time;
                        <else/>
                            ${$originalTableName}_insert_data['update_time'] =$datetime;
                        </if>
                      </if>

                      <if condition="($tableInfo[$columnNameKey] eq 'add_admin_id')">
                            ${$originalTableName}_insert_data['add_admin_id'] =$this->userId;
                      </if>

                      <if condition="($tableInfo[$columnNameKey] eq 'add_admin_name')">
                            ${$originalTableName}_insert_data['add_admin_name'] =$this->userName;
                      </if>

                    </volist>

                    ${$originalTableName}_last_insert_id = ${$tableName}Model->data(${$originalTableName}_insert_data)->add(); 
                    if(${$originalTableName}_last_insert_id){                                       
                        $cnt++;
      				          $table .= "<tr><tr><th>".$k."</th>
                          <if condition="count($listFieldArr) AND is_array($listFieldArr)">
                            <volist name="listFieldArr" id="vvo" key="iio">
                              <volist name="tableInfoArray" id="tableInfo">
                                <if condition="($tableInfo[$columnNameKey] eq $vvo) AND ($tableInfo['column_key'] neq 'PRI') AND ($tableInfo[$columnNameKey] neq 'add_time') AND ($tableInfo[$columnNameKey] neq 'update_time') AND ($tableInfo[$columnNameKey] neq 'add_admin_id') AND ($tableInfo[$columnNameKey] neq 'add_admin_name')">
                                   <th>".${$vvo}."</th>
                                </if>
                              </volist>
                            </volist>
                          </if> 
                          <th>是</th><th>导入成功</th></tr>";
                    }else{
      				        $table .= "<tr><tr><th>".$k."</th>
                          <if condition="count($listFieldArr) AND is_array($listFieldArr)">
                            <volist name="listFieldArr" id="vvo" key="iio">
                              <volist name="tableInfoArray" id="tableInfo">
                                <if condition="($tableInfo[$columnNameKey] eq $vvo) AND ($tableInfo['column_key'] neq 'PRI') AND ($tableInfo[$columnNameKey] neq 'add_time') AND ($tableInfo[$columnNameKey] neq 'update_time') AND ($tableInfo[$columnNameKey] neq 'add_admin_id') AND ($tableInfo[$columnNameKey] neq 'add_admin_name')">
                                   <th>".${$vvo}."</th>
                                </if>
                              </volist>
                            </volist>
                          </if> 
                          <th>否</th><th>插入数据库失败</th></tr>"; 
                    } 
                	}else{
		                  $table .= "<tr><tr><th>".$k."</th>
                          <if condition="count($listFieldArr) AND is_array($listFieldArr)">
                            <volist name="listFieldArr" id="vvo" key="iio">
                              <volist name="tableInfoArray" id="tableInfo">
                                <if condition="($tableInfo[$columnNameKey] eq $vvo) AND ($tableInfo['column_key'] neq 'PRI') AND ($tableInfo[$columnNameKey] neq 'add_time') AND ($tableInfo[$columnNameKey] neq 'update_time') AND ($tableInfo[$columnNameKey] neq 'add_admin_id') AND ($tableInfo[$columnNameKey] neq 'add_admin_name')">
                                   <th>".${$vvo}."</th>
                                </if>
                              </volist>
                            </volist>
                          </if> 
                          <th>否</th><th>该行任何一列数据都不能为空</th></tr>"; 
                	}
                }
            }

            $table .= '</table><br>';

            //记录日志
	        $log_msg=$this->userName.'在'.$datetime.'时候'.'共'.$len_result.'条数据,成功导入'.$cnt.'条数据';
	        $this->save_log($log_msg,${$originalTableName}_last_insert_id);   

			//删除上传原文件
            @unlink($uploaded_file_path);          

            //打印上传反馈记录表
            echo '共'.$len_result.'条表格记录数据,成功导入'.$cnt.'条数据';
            echo $table;

        }

    } 